#ifndef _BUFFER_H_
#define _BUFFER_H_
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stddef.h>
/* typedef -------------------------------------------------------------------*/
struct LoopBuffer
{
    uint8_t     *buffer;                            
    size_t      bufferLength;                       
    uint16_t    _start;                             
    uint16_t    _end;   
    uint16_t    _pointer;      
    uint16_t    _flag;                      
    
	struct LoopBufferEvent
	{
		void (*new)(uint8_t *packet, size_t len);
        void (*full)(void);
	}event;
};

/* define --------------------------------------------------------------------*/
#define LOOP_BUFFER_FULL    (1<<0)
/* macro ---------------------------------------------------------------------*/
/* variables -----------------------------------------------------------------*/
/* function prototypes -------------------------------------------------------*/
void LoopBuffer_Init(struct LoopBuffer *loopBuffer, void *buffer, size_t bufferSize);
void LoopBuffer_Fill(struct LoopBuffer *loopBuffer, void *data, size_t size);
int LoopBuffer_Clip(struct LoopBuffer *loopBuffer, size_t remainCount);
int LoopBuffer_Interate(struct LoopBuffer *loopBuffer, int step, void *param, void (*handler)(void *data, int index, void *param));
void LoopBuffer_RegisterEventNew(struct LoopBuffer *loopBuffer, void (*new)(uint8_t *packet, size_t len));
bool LoopBuffer_IsFull(struct LoopBuffer *loopBuffer);

/* functions -----------------------------------------------------------------*/
#endif
